using System;
using System.Windows.Forms;
using Jbe.TestSuite.Infrastructure.Interface;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.Commands;
using Jbe.TestSuite.Infrastructure.Interface.Services;
using Jbe.TestSuite.Message.Demo.Constants;
using Jbe.TestSuite.Message.Demo.Properties;
using System.Drawing;
using SCSFContrib.CompositeUI.WinForms.SmartPartInfos;

namespace Jbe.TestSuite.Message.Demo
{
    public class ModuleController : WorkItemController
    {
        private IUIElementCreationService uiElementCreationService;

        [ServiceDependency]
        public IUIElementCreationService UIElementCreationService
        {
            set { uiElementCreationService = value; }
        }

        public override void Run()
        {
            IToolBarItem toolBarItem = uiElementCreationService.CreateToolBarItem(
                "Message Demo", Resources.ReportEdit.ToBitmap());
            WorkItem.UIExtensionSites[UIExtensionSiteNames.MainToolbar].Add(toolBarItem);
            toolBarItem.Click += new EventHandler(MessageDemoToolBarItemClick);
        }

        private void ShowMessageDemo()
        {
            IconSmartPartInfo dpInfo = new IconSmartPartInfo("Message Demo", "Message Demo");
            dpInfo.Icon = Resources.ReportEdit;
            DemoView view = WorkItem.SmartParts.AddNew<DemoView>();
            view.Disposed += new EventHandler(ViewDisposed);
            WorkItem.Workspaces[WorkspaceNames.DockPanelWorkspace].Show(view, dpInfo);
        }

        #region Command and Event handler

        private void MessageDemoToolBarItemClick(object sender, EventArgs e)
        {
            ShowMessageDemo();
        }

        private void ViewDisposed(object sender, EventArgs e)
        {
            WorkItem.SmartParts.Remove(sender);
        }

        #endregion
    }
}
